#pragma once
#include<iostream>
#include<assert.h>
using namespace std;

class Stack
{
public:
	Stack(int n = 4)
	{
		a = (int*)malloc(sizeof(int) * n);
		top = capacity = 0;
	}
	Stack(const Stack& st)
	{
		int*tmp = (int*)realloc(a, sizeof(int) * st.top);
		assert(tmp);
		a = tmp;
		memcpy(a, st.a, sizeof(int) * st.top);
		top = st.top;
		capacity = st.capacity;
	}
	~Stack()
	{
		if (a)
		{
			free(a);
			top = capacity = 0;
		}
	}
	Stack& operator=(const Stack& st)
	{
		int* tmp = (int*)realloc(a, sizeof(int) * st.top);
		assert(tmp);
		a = tmp;
		memcpy(a, st.a, sizeof(int) * st.top);
		top = st.top;
		capacity = st.capacity;
		return*this;
	}
	void Push(const int x);
	void Pop();
	int Top();
	int Size();
	bool Empty();
	void Print();
private:
	int* a;
	int top;
	int capacity;
};